//
//  RecommedView.m
//  海角音乐
//
//  Created by dllo on 15/8/6.
//  Copyright (c) 2015年 杨元石. All rights reserved.
//

#import "RecommedView.h"
#import "RecommedModel.h"

@implementation RecommedView

- (id)initWithFrame:(CGRect)frame 
{
    self = [super initWithFrame:frame];
    
    if (self) {
        self.recommedTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-50-64) style:UITableViewStylePlain];
        [self addSubview:self.recommedTableView];
        [_recommedTableView release];
        
        CGFloat cy_height = SCREEN_WIDTH*0.3466667; // 130        
        //网络加载 --- 创建带标题的图片轮播器
        cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(10, SCREEN_WIDTH-20, SCREEN_WIDTH, cy_height) imageURLStringsGroup:nil]; // 模拟网络延时情景
        cycleScrollView2.delegate = self;
        cycleScrollView2.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
        cycleScrollView2.autoScrollTimeInterval = 5.0;
        cycleScrollView2.placeholderImage = [[UIImage imageNamed:@"online_default_big_logo.jpg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        self.recommedTableView.tableHeaderView = cycleScrollView2;
    }
    return self;
}

- (void)getTitleImage:(NSDictionary *)dic
{
    DataArr = [[NSMutableArray alloc] init];
    _url_Arr = [[NSMutableArray alloc] init];

    
    NSArray *array = [dic objectForKey:@"data"];
    for (NSDictionary *bigDic in array) {
        RecommedModel *recoModel = [[RecommedModel alloc] init];
        [recoModel setValuesForKeysWithDictionary:bigDic];
        [DataArr addObject:recoModel];
    }
    for (int i = 0; i < DataArr.count; i++) {
        RecommedModel *recommed = [DataArr objectAtIndex:i];
        NSString *url = recommed.pic_url;
        [_url_Arr addObject:url];
        
    }    
    // 模拟加载延迟
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        cycleScrollView2.imageURLStringsGroup = _url_Arr;
       
    });    
    
}

#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    
    if (DataArr.count > index) {
        RecommedModel *recommedModel = [DataArr objectAtIndex:index];
        [self.delegate gotoNextViewController:recommedModel];

    }

}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
